'use strict';
const dayjs = require("dayjs");
const {getDefaultModelConfig} = require("../../utils/common");

module.exports = app => {
    const { STRING, INTEGER, DATE, TINYINT, BIGINT } = app.Sequelize;
    return app.model.define(
        'Traveler',
        {
            id: {type: INTEGER, primaryKey: true, autoIncrement: true},
            name: {type: STRING(50), allowNull: false, comment: '出行人姓名'},
            id_card: {type: STRING(18), allowNull: false, comment: '身份证号'},
            birth_date: {type: DATE, comment: '出生日期'},
            phone: {type: STRING(11), comment: '联系方式'},
            user_id: {type: BIGINT, allowNull: false, comment: '用户ID'},
            status: {type: TINYINT, defaultValue: 1, comment: '状态：1-正常，0-禁用'},
            ...getDefaultModelConfig(app)
        },
        {
            tableName: 'traveler',
            timestamps: true,
            createdAt: 'create_time',
            updatedAt: 'update_time'
        }
    );

    Traveler.associate = function() {
        app.model.Business.Traveler.belongsTo(app.model.Business.User, {as: 'user', foreignKey: 'user_id'});
        app.model.Business.Traveler.hasMany(app.model.Business.TravelerOrder, {as: 'travelerOrders', foreignKey: 'traveler_id'});
    }
    return Traveler;
}; 